package com.neusoft.dibuy.myarray;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int [] is = {7,9,6,2,5,1,0,3,8,4 };
        bubbleSort(is);
        System.out.println(Arrays.toString(is));
    }
    public static void bubbleSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            boolean flag = false;
            for (int j = 0; j <= arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag = true;
                }
            }
            if (!flag){
                break;
            }
            System.out.println(Arrays.toString(arr));
        }
    }
}
